﻿@model MemberGradeModel
@using CAF.Mvc.JQuery.Datatables.Core;
@{
    var gridPageSize = EngineContext.Current.Resolve<CAF.Infrastructure.Core.Domain.Common.AdminAreaSettings>().GridPageSize;
    ViewBag.Title = T("Admin.ContentManagement.MemberGrades").Text;
    var g = Html.GridToolKit();
    var grid = g.DataGrid("memberGradesGrid", g.Param(x => x.Id)).TableId("table-id").GridKey("Id").PageLength(gridPageSize)
    .MainGrid(
    g.GridColumn(x => x.GradeName, 50),
    g.GridColumn(x => x.Integral, 100),
    g.GridColumn(x => x.IsDefault, 200).DefaultContent("<a href='/admin/membergrade/list/#Id#' class='btn btn-default select' title='" + T("Admin.ContentManagement.MemberGrades.Fields.MarkAsDefault").Text + "'>" + T("Admin.Common.Select").Text + "</a>"),
    g.GridColumn("operation", "" + T("Admin.Common.Operation").Text + "", 100).DefaultContent("<a href='/admin/membergrade/Edit/#Id#' class='btn default btn-xs purple'><i class='fa fa-edit'></i></a>"))
    .Url(Url.Action("List", "MemberGrade")).DefaultTableClass().BindRowCallback("bindRowCallback");
}

@using (Html.BeginForm())
{
    <div class="row">
        <div class="col-md-12">
            <div class="portlet light">
                <div class="section-header sticky">
                    <div class="caption">
                        <i class="icon-equalizer font-red-sunglo"></i>
                        <span class="caption-subject font-red-sunglo bold uppercase"> @T("Admin.ContentManagement.MemberGrades")</span>
                        <span class="caption-helper"></span>
                    </div>
                    <div class="actions">
                        <a href="@Url.Action("Create")" class="btn yellow"><i class="fa fa-plus"></i>@T("Admin.Common.AddNew") </a>
                    </div>
                </div>
                <div class="portlet-body flip-scroll">
                    <div class="portlet">
                        <div class="portlet-title">
                            <div class="caption">
                                <i class="fa fa-search"></i>@T("Admin.Common.List")
                            </div>
                            <div class="tools">

                            </div>
                        </div>
                        <div class="portlet-body">
                            <table id="@grid.GetTableId" class="@grid.GetDefaultTableClass" @Html.Raw(grid.GetFixedLayout ? "style='table-layout:fixed'" : "")>
                                <thead>
                                    <tr>
                                        @foreach (var column in grid.GetColumns)
                                {
                                    if (column.Name == "" + T("Admin.Common.Edit").Text + "")
                                    {

                                        <th class="@column.CssClassHeader">@column.DisplayName</th>

                                    }
                                    else if (column.DisplayName == null)
                                    {

                                        <th class="@column.CssClassHeader"><input type="checkbox" class="group-checkable" data-set="checkboxes"></th>

                                    }
                                    else
                                    {
                                        <th class="@column.CssClassHeader">@column.DisplayName</th>
                                    }

                                }
                                    </tr>

                                </thead>
                                <tbody></tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">

        function bindRowCallback(nRow, aData, iDisplayIndex) {
            var row = $(nRow);
            $('td a.select', row).each(function () {
                var disabled = aData["IsDefault"];
                if (disabled) {
                    $(this).attr("disabled", true);
                    $(this).html("<i class='fa fa-check'></i>@T("Admin.Common.Select")")
                }
                else $(this).removeAttr("disabled");

            });
        }

        $(document).ready(function () {
            @(grid)
            //search button
            $('#btnSearch').click(function () {
                var grid = memberGradesGrid.reload();
                return false;
            });
        });
    </script>
}

